<?php

require_once 'AbstractLocale.class.php';

/**
 * Class locale.
 * @author tiago.professor@gmail.com
 */
class Locale extends AbstractLocale {

    private $gmtTime;
    private $is24;
    private $isSummerTime;

    /**
     * Contructor.
     * <span style="color:red">Don't use this constructor, please use the class LocaleFactory.</span>
     */
    public function __construct($gmtTime, $is24 = false, $isSummerTime = false) {
        $this->setGmtTime($gmtTime);
        $this->setIs24($is24);
        $this->setIsSummerTime($isSummerTime);
    }

    public function getGmtTime() {
        return $this->gmtTime;
    }

    public function setGmtTime($gmtTime) {
        $this->gmtTime = $gmtTime;
    }

    public function is24() {
        return $this->is24;
    }

    public function setIs24($is24) {
        $this->is24 = $is24;
    }

    public function isSummerTime() {
        return $this->isSummerTime;
    }

    public function setIsSummerTime($isSummerTime) {
        $this->isSummerTime = $isSummerTime;
    }

    public function getLocaleTime() {
        //Returns +0100 for example. To indicate the server GMT.
        $serverGmtTime = date('O');

        $modGmt = $this->getGmtTime() % 100;
        $divGmt = (Integer) ($this->getGmtTime() / 100);
        $newGmt = $divGmt + ($modGmt / 60);

        if ($this->isSummerTime) {
            $newGmt += 1;
        }

        $newTime = time() - ($serverGmtTime / 100 * 3600); //Removing server difference
        $newTime += $newGmt * 3600;
        
        //$dtFormat = $this->is24 ? 'Y-m-d H:i:s' : 'Y-m-d h:i:s';
        $dtFormat = 'Y-m-d H:i:s';
        
        $dateRet = date($dtFormat, $newTime);
        return $dateRet;
    }
}

?>
